﻿@{

}

@model netcoreweb.Areas.Admin.Models.Article
<form asp-controller="home" asp-action="EditArticle" method="post">
    <br />
    <div class="title-div">
        <span class="title-span">标题:</span>
        <input asp-for="Title" type="text" class="form-control title-input" placeholder="标题">
        <button id="btnLogin" type="submit" class="btn btn-primary btn-block btn-flat article-save-button">保存</button>
    </div>
    <br />
    <div id="articleEditor">
        <textarea id="articleContent" style="display: none;">@Html.Raw(Model.Context)</textarea>
    </div>
    <div class="col-xs-4">

    </div>
</form>
<link href="~/css/article.css" rel="stylesheet" />
<link href="~/lib/editormd/css/editormd.min.css" rel="stylesheet" />
<link href="~/lib/editormd/css/editormd.preview.min.css" rel="stylesheet" />
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/editormd/editormd.min.js"></script>

<script>
    $(function () {
        testEditor = editormd("articleEditor", {
            width: "99%",
            height: 640,
            syncScrolling: "single",
            path: "/lib/editormd/lib/",
            saveHTMLToTextarea: true,
            emoji: true,
            @* //图片上传
                imageUpload: true,
                imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                imageUploadURL: "/Editor/UpImage/@Model.Id" *@
        });
    });
    $("#articleContent").on('paste', function (ev) {
        var items = (event.clipboardData || event.originalEvent.clipboardData).items;
        for (var index in items) {
            var item = items[index];
            if (item.kind === 'file') {
                var blob = item.getAsFile();
                var reader = new FileReader();
                reader.onload = function (event) {
                    //将剪切板中复制信息转换成一种base64格式字符串
                    var base64 = event.target.result;
                    //ajax上传图片
                    $.ajax({
                        url: "/Editor/UpladFilePIC/@Model.Id",
                        type: 'post',
                        data: { 'base': base64 },
                        async: false,
                        dataType: 'json',
                        success: function (res) {
                            if (res.code == 1)//新一行的图片显示
                                testEditor.insertValue("\n![" + "image.png" + "](" + res.msg + ")");
                        },
                        error: function () {
                            alert('图片上传错误');
                        }
                    });
                }
            }; // data url!
            var url = reader.readAsDataURL(blob);
        }
    });
</script>
